/*
 *  $Id: DescriptedSurface.cs 1238 2011-03-23 11:39:47Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System.IO;

using AgateLib;
using AgateLib.DisplayLib;
using AgateLib.Geometry;

using Nereal.Serialization;

namespace Ragima.UI {
    /// <summary>
    /// Поверхность с описанием содержимого.
    /// </summary>
    public class DescriptedSurface<D, L> where L : DescriptorList<D> where D : class {
        private Surface _surface;
        private L _descriptors;

        public DescriptedSurface(string surfName) {
            _surface = new Surface(surfName);
            var descName = Path.ChangeExtension(surfName, "xml");
            using (var stream = AgateFileProvider.Images.OpenRead(descName))
                _descriptors = Serializer.Default.Deserialize<L>(stream, false);
        }

        public Surface Surface {
            get { return _surface; }
        }

        public L Descriptors {
            get { return _descriptors; }
        }

        public D GetDescriptor(string id) {
            D desc = _descriptors.GetDescriptor(id);
            if (desc == null)
                throw new System.ArgumentException("Requested descriptor not exist.", "id");
            return desc;
        }
    }
}
